#include <stdio.h>
#include <unistd.h>
#include <stdlib.h> // exit
#include <string.h>
#include <errno.h>
#define N 10

typedef void (*callback_t)();

void Worker()
{
    int cnt = 10;
    while(cnt)
    {
        printf("I am a process,pid:%d, ppid:%d, cnt:%d \n",getpid(),getppid(),cnt);
        sleep(1);
        cnt--;
    }
}

void createSubProcess(int n,callback_t cb)
{

    int i = 0;
    for(i = 0; i < n; i++)
    {
        sleep(1);
        pid_t id = fork();
        if(id == 0)
        {
            //子进程
            printf("create child process success,%d\n",i);
            cb();
            exit(0);
        }
    }
}

const char* error_string[]=
{
    "success","open error","other err"
};

int main()
{
    //while(1)
    //{
    //    printf("I am a normal process mypid:%d\n",getpid());
    //    sleep(1);
    //}


    //int ret = 0;
    //printf("before: %d\n",errno);
    //FILE* fp = fopen("./log.txt","r");
    //if(fp == NULL) 
    //{
    //    printf("before: %d, error string:%s\n",errno,strerror(errno));
    //    ret = errno;//是退出码与错误码相同
    //}
    //return ret; 

    //int i = 0;
    //for(i = 0; i<200;i++)
    //{
    //    printf("%d: %s\n",i,strerror(i));
    //}
    //createSubProcess(N,Worker);

    //sleep(100);  

    return 0;//Main函数的返回值，就叫做进程的退出码，0->success,!0->Failed
}
